package com.example.book.crawler.task;

import com.example.book.common.utils.RedisService;
import com.example.book.crawler.entity.CrawlerCatalog;
import com.example.book.crawler.entity.CrawlerContent;
import com.example.book.crawler.pageprocessor.CatalogPageProcessor;
import com.example.book.crawler.service.CrawlerCatalogService;
import com.example.book.crawler.service.CrawlerContentService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;
import us.codecraft.webmagic.scheduler.RedisScheduler;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;

@Component
public class CatalogTask {

    @Autowired
    private CrawlerCatalogService crawlerCatalogService;
    @Autowired
    private RedisService redisService;
    @Autowired
    private CrawlerContentService crawlerContentService;

    @Scheduled(cron = "0 0/5 * * * ?")
    public void initCrawlerCatalog() {
        CrawlerCatalog crawlerCatalog = crawlerCatalogService.getInfoOfByStatusAndAsc();
        if (crawlerCatalog != null) {
            // 抓取并保存
            crawlerCatalogService.initCrawler(crawlerCatalog);
        }
    }


}
